#!/usr/bin/perl
#
# jogcast.pl - edit Podcasts to include jogging interval notices
# Copyright (C) 2005 Paul Roub
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
# The author may be contacted via email at: paul@roub.net
#

use strict;
use File::Copy;
use MP3::Info qw(:DEFAULT :genres);
use splitter;

die "usage: perl jogcast.pl scriptfile MP3file\n" if (@ARGV < 2);

my  $script = $ARGV[0];
my  @inmp3 = @ARGV[1..$#ARGV];
my  $tempdir = '.';
my  $sofar = 0;
my  @parts = ();
my  @edits = ();
my  $partno = 1;
my  $pretend = 0;

if (! -f $script)
{
   die "script file $script not found\n";
}

foreach my $inmp3 (@inmp3)
{
    if (! -f $inmp3)
    {
       die "audio file $inmp3 not found\n";
    }
}

my  $splitter = splitter->new();
$splitter->prep($script, @inmp3);

if (! $splitter->enough())
{
    die $splitter->scriptMinutes() . " minutes required by \"$script\", \"" . join(' + ', @inmp3) .  "\" is only " . $splitter->mp3Minutes() . " minutes long\n";
}

$splitter->edit();
$splitter->moves();



__END__

=head1 NAME

jogcast.pl - edit Podcasts to include jogging interval notices

=head1 SYNOPSIS 

B<perl jogcast.pl> scriptfile MP3file [...]

=head1 AVAILABILITY

Download from L<http://roub.net/apps/jogcast/>

=head1 DESCRIPTION

B<jogcast.pl> splits a list of Podcast MP3 files (I<MP3file>) at 
the intevals specified in a jogging/running script file
(I<scriptfile>); the resulting segments are mixed
with sound bytes containing "run", "walk", "jog"
and "finished" instructions.  

The program warns if the total length of the input MP3 files is too
short for the requested script.  All output files are 
tagged and titled numerically, so most devices 
should play the parts in the proper order.

The author got tired of trying to squint at
the time on his MP3 player while running, and here we are.

=head1 EXAMPLE

  perl jogcast.pl week3.txt YeastRadio20041225.mp3
 
where week3.txt contains:

  walk 5
  jog 1.5
  walk 1.5
  jog 3
  walk 3
  jog 1.5
  walk 1.5
  jog 3
  walk 3

Would produce:

  01 - YeastRadio20041225.mp3   ("walk")
  02 - YeastRadio20041225.mp3   (5 minutes of Podcast)
  03 - YeastRadio20041225.mp3   ("jog")
  04 - YeastRadio20041225.mp3   (1.5 minutes of Podcast)
  05 - YeastRadio20041225.mp3   ("walk")
  06 - YeastRadio20041225.mp3   (1.5 minutes of Podcast)
  07 - YeastRadio20041225.mp3   ("jog")
  08 - YeastRadio20041225.mp3   (3 minutes of Podcast)
  09 - YeastRadio20041225.mp3   ("walk")
  10 - YeastRadio20041225.mp3   (3 minutes of Podcast)
  11 - YeastRadio20041225.mp3   ("jog")
  12 - YeastRadio20041225.mp3   (1.5 minutes of Podcast)
  13 - YeastRadio20041225.mp3   ("walk")
  14 - YeastRadio20041225.mp3   (1.5 minutes of Podcast)
  15 - YeastRadio20041225.mp3   ("jog")
  16 - YeastRadio20041225.mp3   (3 minutes of Podcast)
  17 - YeastRadio20041225.mp3   ("walk")
  18 - YeastRadio20041225.mp3   (3 minutes of Podcast)
  19 - YeastRadio20041225.mp3   ("finished")
  20 - YeastRadio20041225.mp3   (remainder of the Podcast)

You may recognize this as Week 3 of Cool Running's Couch-to-5K
plan (L<http://www.coolrunning.com/engine/2/2_3/181.shtml>).

You can list multiple MP3 files when one is not long enough
for your schedule.  e.g.

  perl jogcast.pl somelongthing.txt YeastRadio20041225.mp3 YeastRadio20051225.mp3

=head1 REQUIREMENTS

=head2 Perl Modules

=over

=item MP3::Info

Available via CPAN: L<http://search.cpan.org/dist/MP3-Info/Info.pm>

=back

=head2 Other software

=over

=item mpgedit

MP3 split/combine utility, available at L<http://mpgedit.org/mpgedit/>.  Must be in your PATH.
In particular, if you're using Cygwin (L<http://cygwin.com>) Perl, you should copy all of 
the mpgedit *.dll and *.exe files to Cygwin's /bin directory.

=back


=head1 AUTHOR AND COPYRIGHT

Paul Roub  <paul@roub.net>  http://roub.net/

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

L<http://www.gnu.org/licenses/licenses.html#GPL>

=head1 VERSION

1.0

=cut

